package es.techideas.appsjam;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class GenericItemizedOverlayM extends ItemizedOverlay<OverlayItem>{

	private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
	private ArrayList<String> itemText = new ArrayList<String>();
	private Context context;

	
	public GenericItemizedOverlayM(Drawable marker,Context context) {
		super(boundCenterBottom(marker));
		this.setContext(context);
		populate();
	}


	public  void clean() {
		overlayItemList.clear();
		populate();
	}

	
	
	public void addItem(GeoPoint p, String title, String snippet){
		if(p != null){
			OverlayItem newItem = new OverlayItem(p, title, snippet);
			overlayItemList.add(newItem);
			itemText.add(snippet);
			populate();
		}
	}




	@Override
	protected OverlayItem createItem(int i) {
		return overlayItemList.get(i);
	}

	@Override
	public int size() {
		return overlayItemList.size();
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		super.draw(canvas, mapView, shadow);
	}


	public void setContext(Context context) {
		this.context = context;
	}


	public Context getContext() {
		return context;
	}
	
	public boolean onTap( int index ) {
		OverlayItem o = overlayItemList.get(index);
		String schedule = o.getSnippet();
		GreenPointsMapActivity.onTapM(schedule);
		return true;
	}
}
